Arrays
Declaration
wAn array is a collection of variables of the same type. Individual array elements are identified by an integer index. In C the index begins at zero and is always written inside square brackets.
w
w int results[20];
w int results_2d[20][5];
w int results_3d[20][5][3];
Where an array is declared in the main function it will usually have details of dimensions included. It is possible to use another type called a pointer in place of an array. This means that dimensions are not fixed immediately, but space can be allocated as required. This is an advanced technique which is only required in certain specialised programs.
Another feature of arrays is their passing as function arguments. A function can be passed an array as an argument without knowing the size of the array's final dimension. So for example if we have a function which inverts a matrix (represented by an array) then the function will be able to invert matrices of different sizes. The drawback is that the function is unable to determine what size the matrix is, so this information will have to be passed as an additional argument.